unit Progress;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, ExtCtrls, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxContainer, cxEdit, dxSkinLilian,cxProgressBar,
  dxSkinsCore, dxSkinLiquidSky, dxSkinSilver, dxSkinsDefaultPainters;

type
  TfrmProgress = class(TForm)
    Timer1: TTimer;
    ProgressBar: TcxProgressBar;
    procedure Timer1Timer(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    FCompleteParts: Integer;
    procedure SetCompleteParts(const Value: Integer);
  public
    { Public declarations }
    class function Execute: TfrmProgress;
    procedure UpdateInfo(const Title,ACaption: string;StepCount: Integer);
    procedure UpdateInfoA(const ACaption: string);
    procedure StepIt(const Steps: Integer);
    property CompleteParts: Integer read FCompleteParts write SetCompleteParts;
  end;

implementation

{$R *.dfm}

class function TfrmProgress.Execute: TfrmProgress;
begin
  Result := Self.Create(Application.MainForm);
  if Assigned(Result) then
  begin
    Result.Show;
  end;
end;

procedure TfrmProgress.FormShow(Sender: TObject);
begin
  ProgressBar.Style.LookAndFeel.NativeStyle := false;
end;

procedure TfrmProgress.SetCompleteParts(const Value: Integer);
begin
  FCompleteParts := Value;
end;

procedure TfrmProgress.StepIt(const Steps: Integer);
begin
  ProgressBar.Position := ProgressBar.Position + Steps;
  CompleteParts := Round(ProgressBar.Position);
  Application.ProcessMessages;
end;

procedure TfrmProgress.Timer1Timer(Sender: TObject);
begin
  inherited;
  if Timer1.Tag > 0 then
  begin
    Timer1.Tag := Timer1.Tag - 1;
    ProgressBar.Position := ProgressBar.Properties.Max - Timer1.Tag;
    CompleteParts := Round(ProgressBar.Position);
  end
  else
    Timer1.Tag := 20;
end;

procedure TfrmProgress.UpdateInfo(const Title, ACaption: string;
  StepCount: Integer);
begin
  if Title <> '' then Caption := Title;
  ProgressBar.Properties.Text := ACaption;
  //if ACaption <> '' then Label1.Caption := ACaption;
  if StepCount > -1 then
    ProgressBar.Properties.Max := StepCount
  else begin
    ProgressBar.Properties.Max := 20;//Timer1.Tag;
    Timer1.Enabled := True;
  end;
  CompleteParts := 0;
  FormStyle := fsStayOnTop;
  Application.ProcessMessages;
end;

procedure TfrmProgress.UpdateInfoA(const ACaption: string);
begin
  //if ACaption <> '' then Label1.Caption := ACaption;
  Application.ProcessMessages;
end;

end.
